// uvm_tb/scoreboard/binary_alu_scoreboard.sv
`ifndef BINARY_ALU_SCOREBOARD_SV
`define BINARY_ALU_SCOREBOARD_SV

class binary_alu_scoreboard extends uvm_scoreboard;

    // ========================================================================
    // UVM Macros
    // ========================================================================
    `uvm_component_utils(binary_alu_scoreboard)

    // ========================================================================
    // Data Members
    // ========================================================================
    uvm_analysis_imp #(binary_alu_transaction, binary_alu_scoreboard) trans_analysis_imp;

    // Queue to hold expected transactions from the sequencer
    binary_alu_transaction expected_queue[$];

    // ========================================================================
    // Constructor
    // ========================================================================
    function new(string name, uvm_component parent);
        super.new(name, parent);
    endfunction

    // ========================================================================
    // UVM Build Phase
    // ========================================================================
    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        trans_analysis_imp = new("trans_analysis_imp", this);
    endfunction

    // ========================================================================
    // UVM Write Implementation
    // ========================================================================
    virtual function void write(binary_alu_transaction trans);
        binary_alu_transaction expected_trans;

        if (expected_queue.size() == 0) begin
            `uvm_info("SCOREBOARD", $sformatf("Received transaction from monitor (no expected data to compare):\n%s",
                                              trans.sprint()), UVM_MEDIUM)
            return;
        end

        expected_trans = expected_queue.pop_front();

        `uvm_info("SCOREBOARD", "Comparing received item with expected item", UVM_MEDIUM)

        // Compare actual vs expected
        if (trans.compare(expected_trans)) begin
            `uvm_info("SCOREBOARD", "PASS: Transaction matches expected", UVM_LOW)
        end else begin
            `uvm_error("SCOREBOARD", "FAIL: Transaction mismatch")
            $display("Expected: %s", expected_trans.sprint());
            $display("Actual: %s", trans.sprint());
        end
    endfunction

    // This function is called from the environment to push expected items
    function void push_expected(binary_alu_transaction trans);
        expected_queue.push_back(trans);
    endfunction

endclass : binary_alu_scoreboard

`endif  // BINARY_ALU_SCOREBOARD_SV
